<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\bootstrap\Modal;
use yii\helpers\Url;

$this->title = '成本项';
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Costs'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<style type="text/css">
    .header{margin:10px;font-weight:bolder;font-size: 16px;}
    .cs1{margin:5px;} 
    .my-cost{margin:10px 0px;border:1px solid #ddd;padding:10px;border-radius: 4px;background-color: #fff;
    -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .05);box-shadow: 0 1px 1px rgba(0, 0, 0, .05);}
</style>

<div class="cost-view">

    <div class="box">
        <div class="box-header">
            <?= Html::a(Yii::t('app', 'Create Cost'), ['create','product_id'=>$product->id], ['class' => 'btn btn-success','data-toggle'=>'modal','data-target'=>'.cost-modal']) ?>
        </div>
        <div class="box-body">
            <div class="my-cost">

               <!--  <div class="header">团队信息</div> -->
                <div class="content-view">
                    <div class="row view-one">
                        <div class="col-md-4">
                            <label>客户名称：</label><?=$product->customer->name?>
                        </div> 
                        <div class="col-md-4">
                            <label>团队名称：</label><?=$product->name?>
                        </div>  
                        <div class="col-md-4">
                            <label>团号：</label><?=$product->code?>
                        </div>     
                    </div> 
              
                    <div class="row view-one">
                        
                        <div class="col-md-4">
                            <label>目的地城市：</label><?=$product->cityInfo?>
                        </div>  
                        <div class="col-md-4">
                            <label>抵离日期：</label><?=$product->begin_date.'/'.$product->end_date?>
                        </div>     
                    </div> 

                    <div class="row view-one">
                        <div class="col-md-4">
                            <label>团人数：</label><?=$product->num?> 人
                        </div> 
                        <div class="col-md-4">
                            <label>总收入：</label><?=$product->price?>
                        </div>  
                        <div class="col-md-4">
                            <label>总成本：</label><?=$product->costPrice?>
                        </div>     
                    </div> 

                    <div class="row view-one">
                        <div class="col-md-4">
                            <label>状态：</label><?=isset(Yii::$app->params['product_status'][$product->status])?Yii::$app->params['product_status'][$product->status]:''?>
                        </div> 
                        <div class="col-md-4">
                            <label>开团人：</label><?=$product->userName?>
                        </div>  
                        <div class="col-md-4">
                            <label>指定操作：</label><?=$product->operName?>
                        </div>     
                    </div> 

                    <div class="row view-one">
                        <div class="col-md-4">
                            <label>创建时间：</label><?=$product->created_at?>
                        </div> 
                        <div class="col-md-4">
                            <label>更新时间：</label><?=$product->updated_at?>
                        </div>  
                        <div class="col-md-4">
                            <label>备注：</label><?=$product->remark?>
                        </div>     
                    </div> 
                 </div>  
            </div>
            <div class="my-cost">
                <div class="header">我的成本项</div>
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>成本项类型</th>
                            <th>供应商</th>
                            <th>支付方式</th>
                            <th>间夜</th>
                            <th>成本</th>
                            <th>备注</th>
                            <th>录入时间</th>
                            <th>状态</th>
                            <th>录入人</th>
                            <th>附件</th>
                            <th>是否确认</th>
                            <th>付款时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if($product->myCost){ ?>
                            <?php foreach($product->myCost as $mcost){ ?>
                            <tr>
                                <td><?=\yii::$app->params['cost_type'][$mcost->cost_type]?></td>
                                <td><?=$mcost->supplier->en_name?></td>
                                <td><?=\yii::$app->params['payment_type'][$mcost->payment]?></td>
                                <td><?=$mcost->dayNum?></td>
                                <td><?=$mcost->price?></td>
                                <td><?=$mcost->remark?></td>
                                <td><?=$mcost->created_at?></td>
                                <td><?=\yii::$app->params['status'][$mcost->status]?></td>
                                <td><?=$mcost->userName?></td>
                                <td><?php if($mcost->file_path){ ?>
                                        <a class="cs1 btn btn-success btn-xs" href="/cost/cost/download?id=<?=$mcost->id?>" >下载附件</a>
                                    <?php }?>
                                </td>
                                <td><?=\yii::$app->params['confirm'][$mcost->confirm];?></td>
                                <td><?=$mcost->payment_time?></td>
                                <td> <?php if($mcost->confirm != 2){ ?>
                                        <?=Html::a('编辑', ['update','id'=>$mcost->id], ['class' => 'cs1 btn btn-info btn-xs','data-toggle'=>'modal','data-target'=>'.cost-modal']) ?><a class="cs1 btn btn-danger btn-xs del" data-id="<?=$mcost->id?>" >删除 </a>

                                <?php }?></td>
                            </tr>    
                        <?php } } ?>
                        
                    </tbody>
                </table>
            </div>   
            <div class="my-cost">
                <div class="header">其他成本项</div>
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>成本项类型</th>
                            <th>供应商</th>
                            <th>支付方式</th>
                            <th>间夜</th>
                            <th>成本</th>
                            <th>备注</th>
                            <th>录入时间</th>
                            <th>状态</th>
                            <th>录入人</th>
                            <th>附件</th>
                            <th>是否确认</th>
                            <th>付款时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if($product->otherCost){ ?>
                            <?php foreach($product->otherCost as $mcost){ ?>
                            <tr>
                                <td><?=\yii::$app->params['cost_type'][$mcost->cost_type]?></td>
                                <td><?=$mcost->supplier->en_name?></td>
                                <td><?=\yii::$app->params['payment_type'][$mcost->payment]?></td>
                                <td><?=$mcost->dayNum?></td>
                                <td><?=$mcost->price?></td>
                                <td><?=$mcost->remark?></td>
                                <td><?=$mcost->created_at?></td>
                                <td><?=\yii::$app->params['status'][$mcost->status]?></td>
                                <td><?=$mcost->userName?></td>
                                <td><?php if($mcost->file_path){ ?>
                                        <a class="cs1 btn btn-success btn-xs" href="/cost/cost/download?id=<?=$mcost->id?>" >下载附件</a>
                                    <?php }?>
                                </td>
                                <td><?=\yii::$app->params['confirm'][$mcost->confirm];?></td>
                                <td><?=$mcost->payment_time?></td>
                            </tr>    
                        <?php } } ?>
                    </tbody>
                </table>
            </div> 

            <div class="my-cost">
                <div class="header">删除的成本项</div>
                <table class="table" style="color: #999;">
                    <thead>
                        <tr>
                            <td>成本项类型</td>
                            <td>供应商</td>
                            <td>支付方式</td>
                            <td>间夜</td>
                            <td>成本</td>
                            <td>备注</td>
                            <td>录入时间</td>
                            <td>状态</td>
                            <td>录入人</td>
                            <td>是否确认</td>
                            <td>付款时间</td>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if($product->delCost){ ?>
                            <?php foreach($product->delCost as $mcost){ ?>
                            <tr>
                                <td><?=\yii::$app->params['cost_type'][$mcost->cost_type]?></td>
                                <td><?=$mcost->supplier->en_name?></td>
                                <td><?=\yii::$app->params['payment_type'][$mcost->payment]?></td>
                                <td><?=$mcost->dayNum?></td>
                                <td><?=$mcost->price?></td>
                                <td><?=$mcost->remark?></td>
                                <td><?=$mcost->created_at?></td>
                                <td><?=\yii::$app->params['status'][$mcost->status]?></td>
                                <td><?=$mcost->userName?></td>
                                <td><?=\yii::$app->params['confirm'][$mcost->confirm];?></td>
                                <td><?=$mcost->payment_time?></td>
                            </tr>    
                        <?php } } ?>
                    </tbody>
                </table>
            </div>

        </div>
    </div>    
    
</div>


<div class="modal fade cost-modal" id="cost-modal" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog " role="document" style="width:600px;">
      <div class="modal-content">
        <!-- 嵌入内容 --> 
      </div>
  </div>
</div>


<?=  yii\web\View::registerJsFile("/js/layer/layer.js",['depends' => 'app\assets\AppAsset']) ?>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">

    // 清除模态框缓存
    $(".cost-modal").on("hidden.bs.modal", function() {
        $(this).removeData("bs.modal");
        //window.location.reload();
    });

    $(".my-cost .del").click(function(){
        var msg = "您真的确定要删除吗?"; 
        if(confirm(msg) == false){ 
             return false;
        }
        var id = $(this).data("id");
        $.ajax({
           type: "get",
           async:false, 
           url: "<?=Url::toRoute(['/cost/cost/del'])?>",
           data: {'id':id},
           success: function(msg){
               var msg = $.parseJSON(msg);
               if(msg.code == 0){
                   layer.msg(msg.message);
                   window.location.reload();
               }else if(msg.code == 1){
                   layer.msg(msg.message);
                   window.location.reload();
               }
            }
       });

    });

</script>
<?php app\components\JsBlock::end() ?>